#!/bin/bash
# Begin tagger
##############
#$# creator : Devon Smith
#%# email: smithde@oclc.org
#$# created : 2010-06-22
#$# title : tagger
#$# description : Command line tagger demo 
########## Define a usage function 
function usage {
    echo "Usage: $this [ format ]"
    echo -e "\t default format = text/x-ner-markup"
    echo -e "\t valid format options = text/x-ner-entities, text/html, application/xml"
    if [ "$1" = "exit" ]; then exit; fi
}
########## Set to "false" to turn verbose off
function echo_stdout { echo "$@"; }
function echo_stderr { echo "$@" >& 2; }
# Set verbose to 'echo_stderr' or 'echo_stdout' to see output trace info
verbose=false
verbose=echo_stdout
$verbose Verbose output on ${verbose##*_}

########## Setup some common paths
# The absolute, canonical ( no ".." ) path to this script
canonical=$(cd -P -- "$(dirname -- "$0")" && printf '%s\n' "$(pwd -P)/$(basename -- "$0")")
# Just the filename of this script
this=$(basename $canonical)
$verbose This: $this
# The directory this script is in
here=$(dirname $canonical)
$verbose Here: $here

########## When the script is being executed
today=$(date +%F)
now=$(date +%H:%M:%S)
$verbose Time: $today $now
##########
if [ "$1" = "-h" ]; then usage 'exit' ; fi
##########
JAVA=$(which java)

format="text/x-ner-markup"
if [ "$1" != "" ]
then
	format="$1"
fi

moduledir=$(dirname $(dirname $here))
$verbose Module Dir: $moduledir

libdir=$(dirname $moduledir)/lib
$verbose Library Dir: $libdir

for script in $(ls classpath.d/*)
do
	if [ -x $script ]
	then
		cp=$($script $libdir)
		if [ "" == "$CP" ]; then CP=$cp; else CP=$CP:$cp; fi
	fi
done
$verbose Classpath: $CP

CLASS=org.oclc.gateman.CmdLineTagger
# Usage: org.oclc.gateman.CmdLineTagger -d input-dir output-dir [ format ]
# Usage: org.oclc.gateman.CmdLineTagger -f batch-file output-file tagger-properties

input_dir=input
output_dir=output

$JAVA -Xmx2000m -cp $CP $CLASS -d $input_dir $output_dir $format

############
# End tagger
# vim:ts=4:indentexpr=
